<template>
    <div class="app-container calendar-list-container">

        <!-- 查询和其他操作 -->
        <div class="filter-container">

        </div>

        <!-- 查询结果 -->
        <el-table size="small" :data="list" v-loading="listLoading" element-loading-text="正在查询中。。。" border fit highlight-current-row>

            <el-table-column align="center" label="id" prop="id" sortable>
            </el-table-column>

            <el-table-column align="center" label="奖品名称" prop="awardName">
            </el-table-column>

            <el-table-column align="center" label="活动数量" prop="num">
            </el-table-column>

            <el-table-column align="center" label="活动日期" prop="activeDate">
            </el-table-column>

            <el-table-column align="center" label="启用状态" prop="deleted">
                <template slot-scope="scope">
                    <el-tag :type="scope.row.deleted ? 'true' : 'false' ">{{ scope.row.deleted ? '已停用' : '已启用' }}</el-tag>
                </template>
            </el-table-column>

            <el-table-column align="center" label="操作" width="200" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button type="danger" size="mini" @click="handleDelete(scope.row)">停用</el-button>
                </template>
            </el-table-column>
        </el-table>

        <!-- 分页 -->
        <div class="pagination-container">
            <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="listQuery.page" :page-sizes="[10,20,30,50]" :page-size="listQuery.limit" layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>

    </div>
</template>

<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #20a0ff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 120px;
  height: 120px;
  line-height: 120px;
  text-align: center;
}
.avatar {
  width: 150px;
  height: 170px;
  display: block;
}
.avatars {
  width: 150px;
  height: 170px;
  display: block;
}
</style>

<script>
import { getPlan, deletePlan } from '@/api/award'
import { getToken } from '@/utils/auth'

export default {
  name: 'Ad',
  computed: {
    headers() {
      return {
        'X-Token': getToken()
      }
    }
  },
  data() {
    return {
      list: undefined,
      total: undefined,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        awardId: undefined,
        sort: '+id'
      },
      dialogFormVisible: false,
      dialogStatus: '',
      downloadLoading: false
    }
  },
  created() {
    this.initData()
  },
  methods: {
    initData() {
      this.listQuery.awardId = this.$route.params.awardId
      this.getList()
    },

    getList() {
      this.listLoading = true
      getPlan(this.listQuery)
        .then(response => {
          this.list = response.data.data.items
          this.total = response.data.data.total
          this.listLoading = false
        })
        .catch(() => {
          this.list = []
          this.total = 0
          this.listLoading = false
        })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listQuery.page = val
      this.getList()
    },

    handleDelete(row) {
      this.$confirm('此操作会停用活动安排, 是否继续?', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deletePlan({ planId: row.id }).then(response => {
          this.$notify({
            title: '成功',
            message: '删除成功',
            type: 'success',
            duration: 2000
          })
          this.getList()
        //   const index = this.list.indexOf(row)
        //   this.list.splice(index, 1)
        })
      })
    }
  }
}
</script>
